home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / tcp / TicTacToe.lha / TicTacToe.AMIRX
Text File  |  1996-09-05  |  12KB  |  332 lines

  1. /*  ___   ___    ___         _         _       ___ _  _
  2.  *   | o _ | _. _ | _  _   _|_ _ ._   /_\ ._ _  | |_)/
  3.  *   | |(_ |(_|(_ |(_)(/_   | (_)|   /   \| | |_|_| \\_
  4.  * -----------------------------------------------------
  5.  *
  6.  *  Version      : 1.0
  7.  *  Release Date : 05/09/96
  8.  *  Written By   : Andrew "Andy" Ricketts
  9.  *  To Do List   : Handle nick changes, quits, etc
  10.  *                 Winner goes first on next game
  11.  *                 Virtual coin to decide who goes first
  12.  *                 Tidy up source code a lot!
  13.  *                 and more useful ! commands
  14.  *                 Scoreboard
  15.  *                 and much more
  16.  *  Coming Soon  : Higher and Lower (Still has a few bugs)
  17.  *                 Trivia (Hasn't got very many questions yet)
  18.  *                 Card games (Only started very recently)
  19.  *                 maybe some sort of RPG (Haven't started)
  20.  *                 loads of other games started
  21.  *
  22.  * It is very easy to play, just start the script, by putting this file in
  23.  * your rexx directory, running AmIRC, and it should appear on your Rexx menu
  24.  * on AmIRC. The game will tell everyone in the current channel how to play.
  25.  * Unfortuanty, you won't be able to run the script AND play it, AmIRC won't
  26.  * allow it, if anyone knows a way around this, please email me.
  27.  *
  28.  * This game is not finished yet, there are still a lot of improvments to be
  29.  * made, but a lot of people have asked me for a copy of this so I had to
  30.  * release this, the first version, in a hurry!
  31.  *
  32.  * If you have any comments about this game or you find any bugs in it, please
  33.  * email me. Don't forget to look out for some of my other games coming soon
  34.  * to an Aminet site near you. Recent information will be available on my
  35.  * homepage.
  36.  *
  37.  * Special Thanks: Everyone in DALnet #DallasTeens for helping me test this
  38.  *                 game so it could be released with NO BUGS(?)
  39.  *
  40.  *      Homepage : http://www.geocities.com/siliconvalley/2874/
  41.  *      EMail    : andrew.ricketts@cccp.net
  42.  *      Find Me  : DALnet #DallasTeens under the nick Andy
  43.  *
  44.  ******************* PLEASE DO NOT ALTER ANY OF THIS FILE ********************/
  45.  
  46.  
  47. ADDRESS "AMIRC.1"
  48. options results
  49.  
  50. 'getchannel'
  51. channel = result
  52.  
  53. player1name = ""
  54. player2name = ""
  55.  
  56. 'SAY /NOTICE 'channel' Tic Tac Toe by Andrew "Andy" Ricketts has been started in 'channel
  57.  
  58. DO FOREVER
  59.  
  60.     board = "         "
  61.     draw = 0
  62.     IF player1name = "" & player2name = "" THEN
  63.     DO
  64.         'SAY /NOTICE 'channel' I am now looking for two players, type !ME if you wanna play.'
  65.     END
  66.     ELSE
  67.     DO
  68.         IF player1name = "" | player2name = "" THEN
  69.         DO
  70.             IF player1name = "" THEN
  71.             DO
  72.                 player1name = player2name
  73.                 player2name = ""
  74.             END
  75.             'SAY /NOTICE 'channel' I am looking for someone to play 'player1name', type !ME if you wanna play.'
  76.         END
  77.     END
  78.     IF player1name = "" | player2name = "" THEN
  79.     DO
  80.         DO UNTIL player1name ~= "" & player2name ~= ""
  81.             DO UNTIL rest = ":!ME"
  82.                 drop rest
  83.                 drop prefix
  84.                 'getline'
  85.                 rest = UPPER(line.rest)
  86.                 prefix = line.prefix
  87.                 dest = line.dest
  88.                 DO loop = 1 TO LENGTH(prefix)
  89.                     char = RIGHT(LEFT(prefix,loop),1)
  90.                     IF char = "!" THEN LEAVE
  91.                 END
  92.                 loop = loop - 1
  93.                 nick = LEFT(prefix,loop)
  94.             END
  95.         
  96.             IF player1name = "" THEN
  97.             DO
  98.                 "SAY /NOTICE "channel" "nick", you have been set as player 1"
  99.                 player1name = nick
  100.             END
  101.             ELSE
  102.             DO
  103.                 IF nick ~= player1name & nick ~= player2name THEN
  104.                 DO
  105.                     "SAY /NOTICE "channel" "nick", you have been set as player 2"
  106.                     player2name = nick
  107.                 END
  108.                 ELSE
  109.                 DO
  110.                     "SAY /NOTICE "channel" "nick", you are already set as a player, a practice mode would be pointless!"
  111.                 END
  112.             END
  113.         END
  114.     END
  115.     'SAY /NOTICE 'channel' The players have been set!'
  116.     'SAY /NOTICE 'channel' 'player1name' Vs 'player2name
  117.     'SAY /NOTICE 'channel' Please do not change your nick during a game!'
  118.     'SAY /NOTICE 'channel' Picking random player...'
  119.  
  120.     first = RANDOM(0,1,TIME(S))
  121.     IF first = 0 THEN
  122.     DO
  123.         'SAY /NOTICE 'channel' 'player1name' goes first!'
  124.         player = "X"
  125.     END
  126.     ELSE
  127.     DO
  128.         'SAY /NOTICE 'channel' 'player2name' goes first!'
  129.         player = "O"
  130.     END
  131.  
  132.     'SAY /NOTICE 'channel' Usage: !GO[#]'
  133.  
  134.     DO FOREVER
  135.  
  136.         DO loop = 1 TO 9 BY 3
  137.             line1 = ''
  138.             line2 = ''
  139.             DO loop2 = 0 TO 2
  140.                 piece = RIGHT(LEFT(board,loop+loop2),1)
  141.                 IF piece = "O" THEN
  142.                 DO
  143.                     line1 = line1'/\'
  144.                     line2 = line2'\/'
  145.                 END
  146.                 IF piece = "X" THEN
  147.                 DO
  148.                     line1 = line1'\/'
  149.                     line2 = line2'/\'
  150.                 END
  151.                 IF piece = " " THEN
  152.                 DO
  153.                     line1 = line1'  '
  154.                     line2 = line2''loop+loop2' '
  155.                 END
  156.                 IF loop2 = 0 | loop2 = 1 THEN
  157.                 DO
  158.                     line1 = line1'|'
  159.                     line2 = line2'|'
  160.                 END
  161.             END
  162.             'SAY /NOTICE 'channel' -->       'line1
  163.             'SAY /NOTICE 'channel' -->       'line2
  164.             IF loop = 1 | loop = 4 THEN 'SAY /NOTICE 'channel' -->       --+--+--'
  165.         END
  166.  
  167.         htop = LEFT(board,3)
  168.         hmiddle = LEFT(RIGHT(board,6),3)
  169.         hbottom = RIGHT(board,3)
  170.         vleft = LEFT(board,1)''LEFT(RIGHT(board,6),1)''LEFT(RIGHT(board,3),1)
  171.         vmiddle = LEFT(RIGHT(board,8),1)''LEFT(RIGHT(board,5),1)''LEFT(RIGHT(board,2),1)
  172.         vright = LEFT(RIGHT(board,7),1)''LEFT(RIGHT(board,4),1)''RIGHT(board,1)
  173.         diag1 = LEFT(board,1)''LEFT(RIGHT(board,5),1)''RIGHT(board,1)
  174.         diag2 = LEFT(RIGHT(board,7),1)''LEFT(RIGHT(board,5),1)''LEFT(RIGHT(board,3),1)
  175.         IF htop = "XXX" | hmiddle = "XXX" | hbottom = "XXX" | vleft = "XXX" | vmiddle = "XXX" | vright = "XXX" | diag1 = "XXX" | diag2 = "XXX" THEN
  176.         DO
  177.             "SAY /NOTICE "channel" "player1name" Won!"
  178.             LEAVE
  179.         END
  180.         IF htop = "OOO" | hmiddle = "OOO" | hbottom = "OOO" | vleft = "OOO" | vmiddle = "OOO" | vright = "OOO" | diag1 = "OOO" | diag2 = "OOO" THEN
  181.         DO
  182.             "SAY /NOTICE "channel" "player2name" Won!"
  183.             LEAVE
  184.         END
  185.  
  186.         draw = draw + 1
  187.         IF draw = 10 THEN
  188.         DO
  189.             "SAY /NOTICE "channel" It's a Draw!"
  190.             LEAVE
  191.         END
  192.  
  193.         IF player = "X" THEN "SAY /NOTICE "channel" Awaiting "player1name"'s Coordinates."
  194.         IF player = "O" THEN "SAY /NOTICE "channel" Awaiting "player2name"'s Coordinates."
  195.  
  196.         current = "X"
  197.         DO UNTIL current = "  "
  198.             coords = true
  199.             DO UNTIL LEFT(rest,4) = ":!GO"
  200.                 drop rest
  201.                 drop dest
  202.                 drop prefix
  203.                 'getline'
  204.                 rest = UPPER(line.rest)
  205.                 dest = line.dest
  206.                 prefix = line.prefix
  207.             END
  208.             DO loop = 1 TO LENGTH(prefix)
  209.                 char = RIGHT(LEFT(prefix,loop),1)
  210.                 IF char = "!" THEN LEAVE
  211.             END
  212.             loop = loop - 1
  213.             nick = LEFT(prefix,loop)
  214.             IF nick = player1name | nick = player2name THEN
  215.             DO
  216.                 pos = RIGHT(rest,1)
  217.                 IF C2D(pos) < 49 | C2D(pos) > 57 | LENGTH(rest) > 5 THEN
  218.                 DO
  219.                     coords = false
  220.                     'SAY /NOTICE 'channel' 'nick', Coordinate not recognised.'
  221.                 END
  222.                 IF nick = player2name & player = "X" | nick = player1name & player = "O" THEN
  223.                 DO
  224.                     "SAY /NOTICE "channel" Hey "nick", it isn't your turn yet! :)"
  225.                     coords = false
  226.                 END
  227.             END
  228.             ELSE
  229.             DO
  230.                 coords = false
  231.                 'SAY /NOTICE 'channel' 'nick', Sorry, you are not involved in this game.'
  232.             END
  233.             IF coords = true THEN
  234.             DO
  235.                 pos = pos - 1
  236.                 current = RIGHT(LEFT(board,pos+1),1)
  237.                 IF current ~= "  " THEN
  238.                 DO
  239.                     "SAY /NOTICE "channel" Illegal Move: Piece already present in that square!"
  240.                 END
  241.             END
  242.         END
  243.         leftboard = LEFT(board,pos)
  244.         rightboard = RIGHT(board,LENGTH(board)-pos-1)
  245.         board = leftboard''player''rightboard
  246.  
  247.         IF player = "O" THEN
  248.             player = "X"
  249.         else
  250.             player = "O"
  251.  
  252.     END
  253.  
  254.     nextplayer1 = ""
  255.     nextplayer2 = ""
  256.     'SAY /NOTICE 'channel' Would either of you like to have another go? !YES or !NO'
  257.     DO UNTIL nextplayer1 ~= "" & nextplayer2 ~= ""
  258.         DO UNTIL rest = ":!YES" | rest = ":!NO"
  259.             drop rest
  260.             drop prefix
  261.             drop dest
  262.             'getline'
  263.             rest = UPPER(line.rest)
  264.             prefix = line.prefix
  265.             dest = line.dest
  266.         END
  267.         DO loop = 1 TO LENGTH(prefix)
  268.             char = RIGHT(LEFT(prefix,loop),1)
  269.             IF char = "!" THEN LEAVE
  270.         END
  271.         loop = loop - 1
  272.         nick = LEFT(prefix,loop)
  273.         IF rest = ":!YES" THEN
  274.         DO
  275.             IF nick = player1name | nick = player2name THEN
  276.             DO
  277.                 "SAY /NOTICE "channel" Good choice "nick"! your name has been put forward for the next game."
  278.                 IF nick = player1name THEN
  279.                 DO
  280.                     nextplayer1 = nick
  281.                     IF nextplayer2 = "" THEN "SAY /NOTICE "channel" What about you "player2name"? !YES or !NO ??"
  282.                 END
  283.                 ELSE
  284.                 DO
  285.                     nextplayer2 = nick
  286.                     IF nextplayer1 = "" THEN "SAY /NOTICE "channel" What about you "player1name"? !YES or !NO ??"
  287.                 END
  288.             END
  289.             ELSE
  290.             DO
  291.                 "SAY /NOTICE "channel" Sorry "nick", you were not involved in the last game, if one of the current players uses !NO to leave the game, you will have a chance you join with the !ME command."
  292.             END
  293.         END
  294.         IF rest = ":!NO" THEN
  295.         DO
  296.             IF nick = player1name | nick = player2name THEN
  297.             DO
  298.                 "SAY /NOTICE "channel" Aww, ok "nick", you will not be in the next game."
  299.                 IF nick = player1name THEN
  300.                 DO
  301.                     nextplayer1 = "#"
  302.                     IF nextplayer2 = "" THEN "SAY /NOTICE "channel" What about you "player2name"? !YES or !NO ??"
  303.                 END
  304.                 ELSE
  305.                 DO
  306.                     nextplayer2 = "#"
  307.                     IF nextplayer1 = "" THEN "SAY /NOTICE "channel" What about you "player1name"? !YES or !NO ??"
  308.                 END
  309.             END
  310.             ELSE
  311.             DO
  312.                 "SAY /NOTICE "channel" "nick", you were not involved in this game, if you object to this game, argue with Andy! ;)"
  313.             END
  314.         END
  315.     END
  316.  
  317.     IF nextplayer1 = "#" THEN nextplayer1 = ""
  318.     IF nextplayer2 = "#" THEN nextplayer2 = ""
  319.  
  320.     IF nextplayer1 = "" & nextplayer2 = "" THEN
  321.     DO
  322.         "SAY /NOTICE "channel" Both players dropped out."
  323.         "SAY /NOTICE "channel" GAME OVER!!"
  324.         "SAY /NOTICE "channel" Please send comments to andrew.ricketts@cccp.net"
  325.         EXIT
  326.     END
  327.  
  328.     player1name = nextplayer1
  329.     player2name = nextplayer2
  330.  
  331. END
  332.